/**
 * events
 */

document.addEventListener('load', function() {
    FastClick.attach(document.body);
}, false);

document.addEventListener('appready', function() {
    setTimeout(function() {
        navigator.splashscreen.hide();
    }, 1000);

    window.plugins.AdMob.setOptions({
        bannerAtTop: false, // set to true, to put banner at top
        overlap: false, // set to true, to allow banner overlap webview
        offsetTopBar: false, // set to true to avoid ios7 status bar overlap
        isTesting: false, // receiving test ad
        autoShow: true // auto show interstitial ad when loaded
    });

    if (device.version.search('4.1') !== 0) {
        console.log('ADS OFF - version 4.1 (' + device.version + ')');
        setTimeout(function() {
            // display the banner ads
            console.log('ads banner');
            window.plugins.AdMob.createBannerView({
                publisherId: 'ca-app-pub-6465819007267041/3067154813'
            });
        }, 2000);
    }

}, false);

var eventGameStart = 0;
document.addEventListener('gamestart', function() {
    eventGameStart++;

    // popup ad every secund game start
    if (eventGameStart % 2 === 0) {
        console.log('ads interstitial');
        // display the interstitial ads
        window.plugins.AdMob.createInterstitialView({
            publisherId: 'ca-app-pub-6465819007267041/5651323618'
        });
    }
}, false);

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    // when all is done, execute bootstrap angular application
    angular.bootstrap(document, ['myApp']);
}
